#include "stdafx.h"
#include "Hand.h"
#include "HandInfo.h"
#include "StealAttHandInfoBuilder.h"

// raised when folded to in the cutoff, button, or small blind
// dealer always sb if heads up

void StealAttHandInfoBuilder::Fill(HandInfo &handInfo, const Hand &hand)
{
	list<Action> actions = hand.Actions();
	list<Action>::const_iterator actionIt;
	bool isRaisedOrCalledPot = false;
	for (actionIt = actions.begin(); actionIt != actions.end(); actionIt++)
	{
		if (isRaisedOrCalledPot || actionIt->StreetPos() != PREFLOP)
			return;

		if (actionIt->ActionType() == POST)
			continue;

		bool isPlayerSb = handInfo.PlayerInfo(actionIt->PlayerName()).MyPlayer().IsSb();
		bool isPlayerButton = handInfo.PlayerInfo(actionIt->PlayerName()).MyPlayer().IsButton();
		bool isPlayerCutoff = handInfo.PlayerInfo(actionIt->PlayerName()).Left()->MyPlayer().IsButton();
		bool isPlayerInStealPos = isPlayerSb || isPlayerButton || isPlayerCutoff;

		if (isPlayerInStealPos)			
		{
			// player has opportunity to steal
			handInfo.PlayerInfo(actionIt->PlayerName()).StealOp(true);

			if (actionIt->ActionType() == RAISE)
			{
				// player attempted to steal
				handInfo.PlayerInfo(actionIt->PlayerName()).StealAttempt(true);
				isRaisedOrCalledPot = true;
			}
		}

		if (actionIt->ActionType() == RAISE || actionIt->ActionType() == CALL)
		{
			isRaisedOrCalledPot = true;
		}
	}
}